﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApiClient.Contexts;
using WebApiClient;

namespace Rest.WebApiClient.Contracts
{
    class ApiTokenFilter : IApiActionFilter
    {
        private string token { get; set; }
        public ApiTokenFilter(string token)
        {
            this.token = token;
        }
        public Task OnBeginRequestAsync(ApiActionContext context)
        {
            context.RequestMessage.Headers.Add("Authorization", $"Basic {token}");

            return Task.FromResult<object>(null);
        }

        public Task OnEndRequestAsync(ApiActionContext context)
        {
            return Task.FromResult<object>(null);
        }
    }
}
